package com.ykt.model;

import com.ykt.common.utils.UB;

import java.util.List;

/**
 * 客户端版本
 *
 * @author long.hua
 * @version 1.0.0
 * @since 2016-02-15 23:23
 */
public class ClientVersion extends BaseModel<ClientVersion> {
    private static final long serialVersionUID = 1L;

    public static final String version_name = "version_name";
    public static final String version_code = "version_code";
    public static final String download_url = "download_url";
    public static final String type = "type";


    public static final ClientVersion dao = new ClientVersion();


    public interface Type {
        int USER = 0;
        int MERCHANT = 1;
    }


    public String getVersionName() {
        return getStr(version_name);
    }

    public String getVersionCode() {
        return getStr(version_code);
    }

    public int getStatus(){
        return UB.i(getInt(type), -1);
    }

    public String getDownloadUrl() {
        return getStr(download_url);
    }

    public List<ClientVersion> findByVersionCode(int versionCode, int type){
        String sql = "SELECT id, version_name versionName, version_code versionCode, " +
                        "download_url downloadUrl, created_time createdTime" +
                " FROM client_version " +
                " WHERE version_code > ? and type = ? order by version_code desc";

        return this.find(sql, versionCode, type);
    }
}
